package net.confinanz.client.frontend;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Font;

import java.util.Vector;

import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import net.confinanz.client.data.Kontakt;
import net.confinanz.client.data.Ansprechpartner;

public class AnsprechpartnerFrame extends JFrame {

	private static final long serialVersionUID = -7562302643308630131L;
	
	private JList<Ansprechpartner> list = new JList<Ansprechpartner>();
	
	private JPanel contentPane;
	private JLabel labelName2;
	private JLabel labelTelefon2 ;
	private JLabel labelFax2;
	private JLabel labelEmail2;

	public AnsprechpartnerFrame() {		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0};
		gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		JPanel panelAnsprechpartner = new JPanel();
		panelAnsprechpartner.setBorder(new TitledBorder(null, "Ansprechpartner", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GridBagConstraints gbc_panelAnsprechpartner = new GridBagConstraints();
		gbc_panelAnsprechpartner.fill = GridBagConstraints.BOTH;
		gbc_panelAnsprechpartner.gridx = 0;
		gbc_panelAnsprechpartner.gridy = 0;
		contentPane.add(panelAnsprechpartner, gbc_panelAnsprechpartner);
		GridBagLayout gbl_panelAnsprechpartner = new GridBagLayout();
		gbl_panelAnsprechpartner.columnWidths = new int[]{0, 0, 0, 0};
		gbl_panelAnsprechpartner.rowHeights = new int[]{0, 0, 0, 0, 0};
		gbl_panelAnsprechpartner.columnWeights = new double[]{1.0, 0.0, 1.0, Double.MIN_VALUE};
		gbl_panelAnsprechpartner.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panelAnsprechpartner.setLayout(gbl_panelAnsprechpartner);
		
		JScrollPane scrollAnsprechpartner = new JScrollPane();
		scrollAnsprechpartner.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		GridBagConstraints gbc_scrollAnsprechpartner = new GridBagConstraints();
		gbc_scrollAnsprechpartner.fill = GridBagConstraints.BOTH;
		gbc_scrollAnsprechpartner.gridheight = 5;
		gbc_scrollAnsprechpartner.insets = new Insets(5, 10, 5, 10);
		gbc_scrollAnsprechpartner.gridx = 0;
		gbc_scrollAnsprechpartner.gridy = 0;
		scrollAnsprechpartner.setPreferredSize(new Dimension(200,100));
		panelAnsprechpartner.add(scrollAnsprechpartner, gbc_scrollAnsprechpartner);
		
		scrollAnsprechpartner.setViewportView(this.list);
		this.list.setFont(new Font("Calibri", Font.PLAIN, 12));
		
		JLabel lblName = new JLabel("Name");
		lblName.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_lblName = new GridBagConstraints();
		gbc_lblName.insets = new Insets(10, 10, 5, 5);
		gbc_lblName.anchor = GridBagConstraints.WEST;
		gbc_lblName.gridx = 1;
		gbc_lblName.gridy = 0;
		panelAnsprechpartner.add(lblName, gbc_lblName);
		
		labelName2 = new JLabel("<Name>");
		labelName2.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_labelName2 = new GridBagConstraints();
		gbc_labelName2.anchor = GridBagConstraints.WEST;
		gbc_labelName2.insets = new Insets(10, 10, 5, 0);
		gbc_labelName2.gridx = 2;
		gbc_labelName2.gridy = 0;
		panelAnsprechpartner.add(labelName2, gbc_labelName2);
		
		JLabel lblNewLabel = new JLabel("Telefon");
		lblNewLabel.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(5, 10, 5, 5);
		gbc_lblNewLabel.gridx = 1;
		gbc_lblNewLabel.gridy = 1;
		panelAnsprechpartner.add(lblNewLabel, gbc_lblNewLabel);
		
		labelTelefon2 = new JLabel("<Telefon>");
		labelTelefon2.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_labelTelefon2 = new GridBagConstraints();
		gbc_labelTelefon2.anchor = GridBagConstraints.WEST;
		gbc_labelTelefon2.insets = new Insets(5, 10, 5, 0);
		gbc_labelTelefon2.gridx = 2;
		gbc_labelTelefon2.gridy = 1;
		panelAnsprechpartner.add(labelTelefon2, gbc_labelTelefon2);
		
		JLabel lblFax = new JLabel("Fax");
		lblFax.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_lblFax = new GridBagConstraints();
		gbc_lblFax.anchor = GridBagConstraints.WEST;
		gbc_lblFax.insets = new Insets(5, 10, 5, 5);
		gbc_lblFax.gridx = 1;
		gbc_lblFax.gridy = 2;
		panelAnsprechpartner.add(lblFax, gbc_lblFax);
		
		labelFax2 = new JLabel("<Fax>");
		labelFax2.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_labelFax2 = new GridBagConstraints();
		gbc_labelFax2.anchor = GridBagConstraints.WEST;
		gbc_labelFax2.insets = new Insets(5, 10, 5, 0);
		gbc_labelFax2.gridx = 2;
		gbc_labelFax2.gridy = 2;
		panelAnsprechpartner.add(labelFax2, gbc_labelFax2);
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_lblEmail = new GridBagConstraints();
		gbc_lblEmail.anchor = GridBagConstraints.WEST;
		gbc_lblEmail.insets = new Insets(5, 10, 0, 5);
		gbc_lblEmail.gridx = 1;
		gbc_lblEmail.gridy = 3;
		panelAnsprechpartner.add(lblEmail, gbc_lblEmail);
		
		labelEmail2 = new JLabel("<Email>");
		labelEmail2.setFont(new Font("Calibri", Font.PLAIN, 12));
		GridBagConstraints gbc_labelEmail2 = new GridBagConstraints();
		gbc_labelEmail2.insets = new Insets(5, 10, 0, 0);
		gbc_labelEmail2.anchor = GridBagConstraints.WEST;
		gbc_labelEmail2.gridx = 2;
		gbc_labelEmail2.gridy = 3;
		panelAnsprechpartner.add(labelEmail2, gbc_labelEmail2);
		
		Ansprechpartner partner = new Ansprechpartner();
		loadAnsprechpartner(partner);
		
		setResizable(false);
		setAlwaysOnTop(true);
		setVisible(true);
	}
	
	private void loadAnsprechpartner(Ansprechpartner partner){
		Vector<Kontakt> kontakte = partner.getKontakte();
		labelName2.setText(partner.getName());
		
		for(Kontakt k : kontakte){
			if(k.getTyp().equals("Telefon")){
				labelTelefon2.setText(k.getAdresse());
			}
			
			if(k.getTyp().equals("Fax")){
				labelFax2.setText(k.getAdresse());
			}
			
			if(k.getTyp().equals("Email")){
				labelEmail2.setText(k.getAdresse());
			}			
		}
	}
}
